package com.csdj.t309.papermanage.controller;

import com.csdj.t309.papermanage.common.WebResult;
import com.csdj.t309.papermanage.entity.TPaper;
import com.csdj.t309.papermanage.service.TpaperService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/tpaper")
public class TpaperController {
    @Resource
    private TpaperService tpaperService;

    private WebResult webResult;

    @ResponseBody
    @GetMapping("/seltps")
    public WebResult seltps(@RequestParam(required = true, defaultValue = "1") Integer page){
        PageHelper.startPage(page,1);
        List<TPaper> posts = tpaperService.selTps();
        PageInfo<TPaper> p = new PageInfo<>(posts);
        webResult = new WebResult();
        webResult.putData("posts",posts).putData("p",p);
        return webResult;
    }

    @ResponseBody
    @GetMapping("/delTp")
    public WebResult delTp(@RequestParam(value = "id",required = false) Integer id){
        Integer result = tpaperService.delTp(id);
        if(result>0){
            webResult = new WebResult();
            webResult.putData("result",result);
            return webResult;
        }
        return null;
    }

    @ResponseBody
    @GetMapping("/insertTp")
    public WebResult insertTp(){
        TPaper tPaper = new TPaper();
        Integer num = tpaperService.insertTp(tPaper);
        if(num>0){
            webResult = new WebResult();
            webResult.putData("num",num);
            return webResult;
        }
        return null;
    }
}
